#!/bin/bash
set -e

echo "开始构建dip6 deb包..."

# 1. 构建可执行文件
echo "1. 构建可执行文件..."
./build.sh

# 2. 复制可执行文件到deb包目录
echo "2. 复制可执行文件..."
cp dip6 deb-package/opt/dip6/
chmod +x deb-package/opt/dip6/dip6

# 3. 设置文件权限
echo "3. 设置文件权限..."
chmod 755 deb-package/opt/dip6/dip6
chmod 644 deb-package/etc/systemd/system/dip6.service

# 4. 构建deb包
echo "4. 构建deb包..."
dpkg-deb --build deb-package dip6_1.0.0_amd64.deb

# 5. 清理临时文件
echo "5. 清理临时文件..."
rm -f dip6

echo "构建完成！deb包: dip6_1.0.0_amd64.deb"
echo ""
echo "安装命令: sudo dpkg -i dip6_1.0.0_amd64.deb"
echo "卸载命令: sudo dpkg -r dip6"
